package com.example.albumphoto

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager2.widget.ViewPager2

class PhotoDetailActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_photo_detail)

        val photosArrId = intent.getIntExtra(DataFactory.EXTRA_PHOTOS_ARR, 0)
        val position = intent.getIntExtra(DataFactory.EXTRA_POSITION, 0)
        if(photosArrId > 0) {
            val photos = DataFactory.getDetailDatas(this, photosArrId)
            setupViewPager(photos, position)
        }
    }

    private fun setupViewPager(photos: List<Int>, initialPosition: Int) {
        val viewPager = findViewById<ViewPager2>(R.id.viewPager)
        viewPager.adapter = PhotoPagerAdapter(photos)
        viewPager.setCurrentItem(initialPosition, false)

        // 添加页面切换监听
        viewPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                // 更新标题或其他UI
                title = "${position + 1}/${photos.size}"
            }
        })
    }
}